//
//  AppDelegate.h
//
//
//  Created by zhangyuv.
//  Copyright (c) 2013年 yonyou. All rights reserved.
//

#import "@{nameOfClass}.h"
@{importChildHs}
@implementation @{nameOfClass}
@synthesize @{id} = _@{id};
@synthesize parentController = _parentController;
@synthesize currentContainer = _currentContainer;
@synthesize contextDictionary = _contextDictionary;
@{addChildSynthesizes}
@{controllerC};
@{context};

- (id)initWithParentCtl:(UIViewController*) parentCtl
{
    self = [super initWithNibName:nil bundle:nil];
    if (self) {
        if(parentCtl){
            self.parentController = parentCtl;
        }else{
            self.parentController = self;
        }
        _@{id} = _viewObject;
        @{selfView}
        _context = [[UMEntityContext alloc]init];
		_ctx = _context;
    }
	return self;
}
- (void)loadView
{
	[super loadView];
}

- (void)viewDidLoad
{
	[super viewDidLoad];
	AppDelegate* appDelegate = [[UIApplication sharedApplication] delegate];
	_currentContainer = [appDelegate currentContainer];
	[_currentContainer initController:ModelName];
	//[_currentContainer initController:@"CustomerContentController"];
	//[_currentContainer initController:@"CustomerContentControllerEx"];

	NSMutableArray* tabPageControllers_array = [NSMutableArray arrayWithCapacity:1];
	@{umcontextInit}
	@{initChilds}
	@{addChilds}

	[self setUMViewControllers:tabPageControllers_array animated:NO];

	@{setviewDidLoads}
}

- (void)viewWillAppear:(BOOL)animated
{
	[super viewWillAppear:animated];
	[SysContext getInstance].CurrentViewController = self;
}
- (void)viewDidAppear:(BOOL)animated
{
	[super viewDidAppear:animated];
	    AppDelegate* appDelegate = [[UIApplication sharedApplication] delegate];
    NSString* result_str = [appDelegate.plugDict objectForKey:@"result"];
    if(result_str){
        [self dataBind:result_str];
    }

	[SysContext getInstance].CurrentViewController = self;
    @{onload}
}
- (void)viewDidUnload
{
	[super viewDidUnload];
}
- (void)dispacherEventToWebView:(NSString*)params
{
	[webView.m_jsBridge callHandler:@"eventdispacher" data:params];
	[_currentContainer DataBinding:self jsonData:params];
}
-(void)onInit{
    [_currentContainer onInit:controllerC];
}
-(void)onLoad{
    [_currentContainer onLoad:controllerC];
}
-(void)onDataBinding{
    //here do databinding
    NSString *context = [_currentContainer getModel:ModelName];
    _contextDictionary = [context objectFromJSONString];
    [self dataBind:_contextDictionary];
}
-(void)onComplete{
    [_currentContainer onComplete:controllerC];
    
    //common message: {"error":["网络无法连接！"],"warnning":[]}
    NSString *msg = [_currentContainer getMessage];
    //[self dumpMsg:msg];
    
}
- (void)dataBind:(NSDictionary*) dic{
	_contextDictionary = dic;
	@{dataBinds}
}
@{actions}
@end